package com.haixiaoke.saas.manage.messageCenter.controller;

import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.messageCenter.domain.MessageChannel;
import com.haixiaoke.saas.messageCenter.service.IMessageChannelService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 机构消息渠道信息Controller
 *
 * @author xiaolong
 * @date 2024-11-08
 */
@RestController
@RequestMapping("/manage/messageCenter/channel")
public class ManageMessageChannelController extends BaseController {
    @Autowired
    private IMessageChannelService messageChannelService;

    /**
     * 查询机构消息渠道信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:messageChannel:list')")
    @GetMapping("/list")
    public TableDataInfo list(MessageChannel messageChannel) {
        startPage();
        List<MessageChannel> list = messageChannelService.selectMessageChannelList(messageChannel);
        return getDataTable(list);
    }

    /**
     * 获取机构消息渠道信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:messageChannel:query')")
    @GetMapping(value = "/{messageChannelId}")
    public AjaxResult getInfo(@PathVariable("messageChannelId") Long messageChannelId) {
        return success(messageChannelService.selectMessageChannelByMessageChannelId(messageChannelId));
    }

    /**
     * 根据机构id获取机构消息渠道详细信息
     */
    @GetMapping(value = "/byTenantId/{tenantId}")
    public AjaxResult getInfoByTenantId(@PathVariable("tenantId") String tenantId) {
        return success(messageChannelService.getInfoByTenantId(tenantId));
    }

    /**
     * 新增机构消息渠道信息
     */
    @PreAuthorize("@ss.hasPermi('manage:messageChannel:add')")
    @PostMapping
    public AjaxResult add(@RequestBody @Valid MessageChannel messageChannel) {
        messageChannel.setCreateBy(getUsername());
        return toAjax(messageChannelService.insertMessageChannel(messageChannel));
    }

    /**
     * 修改机构消息渠道信息
     */
    @PreAuthorize("@ss.hasPermi('manage:messageChannel:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody MessageChannel messageChannel) {
        messageChannel.setUpdateBy(getUsername());
        return toAjax(messageChannelService.updateMessageChannel(messageChannel));
    }

    /**
     * 删除机构消息渠道信息
     */
    @PreAuthorize("@ss.hasPermi('manage:messageChannel:remove')")
    @DeleteMapping("/{messageChannelId}")
    public AjaxResult remove(@PathVariable Long messageChannelId) {
        return toAjax(messageChannelService.deleteMessageChannelByMessageChannelId(messageChannelId));
    }

    /**
     * 校验该渠道是否关联消息模版
     */
    @PreAuthorize("@ss.hasPermi('manage:messageChannel:verify')")
    @GetMapping(value = "/verify")
    public AjaxResult verify(MessageChannel messageChannel) {
        return success(messageChannelService.verifyMessageChannel(messageChannel));
    }
}
